﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BASE;


public partial class diemthanhphan : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Utils.getStringSession("masv") == "")
        {
            Response.End();
        }

        busDiem busD = new busDiem();
        List<entDiem> lst = new List<entDiem>();
        lst = busD.getDiemThanhPhan(Utils.getStringQuery("id"), Utils.getStringSession("masv"));
        repe_d.DataSource = lst;
        repe_d.DataBind();
    }
    protected void btn_ok_Click(object sender, EventArgs e)
    {
        busSinhVien busSV = new busSinhVien();
        if (busSV.checkUpdateLyLich(Utils.getStringSession("masv")) == false)
        {
            lb_me.Text = "Ban chưa cập nhật lý lịch nên không được sử dụng chức năng này";
            return;
        }
        if (txt_nd.Text == "")
        {
            lb_me.Text = "Lỗi không được để trống";
            return;
        }
        else
        {
            lb_me.Text = "";
        }
        busDiem busD = new busDiem();
        List<entDiem> lst = new List<entDiem>();
        lst = busD.getDiemThanhPhan(Utils.getStringQuery("id"), Utils.getStringSession("masv"));
        if (lst.Count > 0)
        {
            string strDiem = " <table style=\"width: 300px; background: #f9f9f9;border: none;margin-top: 5px;border: solid 1px #dedddd;\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" class=\"view-table\"><tr> <td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\" colspan=\"2\" align=center > Thông tin điêm thi </td></tr><tr> <td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\"> Mã môn </td> <td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + lst[0].MaMon + "</td></tr><tr> <td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\"> Tên môn </td> <td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + lst[0].TenMon + "</td></tr><tr> <td> Lớp môn </td> <td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + lst[0].LopMonID + "</td></tr>";


            foreach (entDiem item in lst)
            {
                strDiem += " <tr><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">Điểm " + item.LoaiDiem + "</td><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + item.Diem2 + "</td></tr>";
            }

            strDiem += "  </table>";
            List<entUser> lstUser = new List<entUser>();
            busUser busU = new busUser();
            entSinhVien entSV = new entSinhVien();
        

            entSV = busSV.getSinhVienByMaSV(Utils.getStringSession("masv"));
            lstUser = busU.getUserNhanGopY(3, entSV.Khoa);

            List<String> lstTomail = new List<string>();

            foreach (entUser item in lstUser)
            {
                lstTomail.Add(item.Email);
            }
           

            //lay thong tin sinh vien

            string strSinhVien = "<table style=\"width: 100%; background: #f9f9f9;border: none;margin-top: 5px;border: solid 1px #dedddd;\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" class=\"view-table\"><tr><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\" colspan=\"2\">Thông tin sinh viên</td></tr><tr><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">Họ tên</td><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + entSV.Ho + " " + entSV.Ten + "</td></tr><tr><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">Mã sinh viên</td><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + entSV.MaSinhVien + "</td></tr><tr><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">Lớp</td><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + entSV.MaLop+ "</td></tr><tr><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">Email</td><td style=\" padding-left: 5px;padding-right: 5px !important;border-left: solid 1px #dbdbdb;border-bottom: solid 1px #dbdbdb;border-collapse: separate;\">" + entSV.Email + "</td></tr></table>";
            string strMain = " <table><tr><td valign=\"top\">" + strSinhVien + "</td><td valign=\"top\">" + strDiem + "</td></tr></table>";
            string strBody="";
            strBody+= txt_nd.Text + "<hr>" + strMain + "<hr> Lưu ý: Mail thông báo thắc mắc điểm của sinh viên vui lòng không trả lời mail này";
            strBody += "              <br>";
            string strBody2 = "<table ><tr><td>"+strBody+"</td></tr></table>";
            //cap nhat vao dataabase
            //li.Text = strBody2;
            //gui mail            
            Utils.SendMail(lstTomail, strBody2);
           
        }
    }
}